"""
这是用来找到翻译出错的文件
"""
import os
import re
import shutil
import threading
import Functional.LanguageFunction


def main():
    # 待处理文件夹
    file_root = input("please file path: ")
    try:
        file_root_path = file_root
    except:
        print("input erro")

    ss = []
    i = 0
    for root, dirs, files in os.walk(file_root_path):
        error_path = root + '/tyerror'
        # 错误文件路径
        state = os.path.exists(error_path)
        # 路径不存在则创建
        if state:
            print('目录已存在')
        else:
            os.makedirs(error_path)
        for file in files:
            isneqtxt = re.findall(r'''neq.txt''', file, re.S)
            if len(isneqtxt):
                filepath = root + '/' + file
                # filetxt = open(filepath)
                with open(filepath, 'r', encoding='utf-8') as filetxt:
                    fileline = filetxt.readline()
                    j = 0
                    while not fileline:
                        fileline = filetxt.readline()
                        j = j+1
                        if j >= 10:
                            break
                filelangue = Functional.LanguageFunction.Languagefunction().recongnizelanguage(fileline)
                if filelangue != "LANGUAGEYY":
                    xmlfile = re.sub(r'''neq.txt''', r'''n.xml''', file)
                    xmlpath = root + '/' + xmlfile
                    shutil.copy(filepath, error_path)
                    shutil.copy(xmlpath, error_path)
                    i = i+1
        print(i)
        break


if __name__ == '__main__':
    main()